﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using LGSVR.Common;

namespace LGSVR_WEB.sys
{
    public partial class OpLogList : DataBasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserID"] == null)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "out", "<script>alert('系统超时或服务器故障，请退出重新登录！');window.parent.parent.navigate('../Logout.aspx');</script>");
            }
            if (!IsPostBack)
            {
                innit();
                gvDataBind("");
            }
        }

        private void gvDataBind(string strWhere)
        {
            int pageIndex;

            if (!string.IsNullOrEmpty(Request.QueryString["pg"]) && Utils.IsNumber(Request.QueryString["pg"]))
            {
                pageIndex = int.Parse(Request.QueryString["pg"]);
            }
            else
            {
                pageIndex = 1;
            }
            DataTable dt;
            int totalRS;

            dt = GetList("opLog", " opTime desc ", strWhere, pageIndex, PageSize, out totalRS);
            rptBody.DataSource = dt;
            rptBody.DataBind();
            SplitHtmlCode = Split.GetHtmlCode("OpLogList.aspx", 8, pageIndex, PageSize, totalRS);
        }
        private void innit()
        {

            dropopType.DataSource = Utils.EnumToDataTable(typeof(LogOpType));
            dropopType.DataTextField = "Name";
            dropopType.DataValueField = "ID";
            dropopType.DataBind();

            dropopType.Items.Insert(0, new ListItem("-请选择-", ""));

            txtStartTime.Attributes.Add("readonly", "readonly");
            txtEndTime.Attributes.Add("readonly", "readonly");

        }
        protected void Search(object sender, CommandEventArgs e)
        {
            string strWhere = "";
            if (dropopType.SelectedValue != "")
            {
                strWhere = " and opType=" + dropopType.SelectedValue;

            }
            if (txtStartTime.Text.Trim() != "")
            {
                strWhere += " and opTime>='" + txtStartTime.Text + "'";
            }
            if (txtEndTime.Text.Trim() != "")
            { 
                strWhere += " and opTime<='" + txtEndTime.Text + "'"; 
            }
            gvDataBind(strWhere);
        }
    }
}